package com.liaoban.app.biz;

import android.content.Context;
import android.text.TextUtils;

import com.liaoban.app.api.type.CallReq;
import com.liaoban.app.api.type.Grade;
import com.liaoban.app.api.type.MessageIndex;
import com.liaoban.app.api.type.Notice;
import com.liaoban.app.api.manager.HttpManager;
import com.liaoban.app.api.type.Anchor;
import com.liaoban.app.api.type.Band;
import com.liaoban.app.api.type.Banner;
import com.liaoban.app.api.type.Black;
import com.liaoban.app.api.type.CallHistory;
import com.liaoban.app.api.type.Earn;
import com.liaoban.app.api.type.Follow;
import com.liaoban.app.api.type.Gift;
import com.liaoban.app.api.type.Img;
import com.liaoban.app.api.type.MyVideo;
import com.liaoban.app.api.type.PayIndex;
import com.liaoban.app.api.type.PayIndex2Request;
import com.liaoban.app.api.type.PayStatus;
import com.liaoban.app.api.type.Profit;
import com.liaoban.app.api.type.Rank;
import com.liaoban.app.api.type.RecommendName;
import com.liaoban.app.api.type.Report;
import com.liaoban.app.api.type.ShareTixian;
import com.liaoban.app.api.type.ThreeLoginReq;
import com.liaoban.app.api.type.TiXian;
import com.liaoban.app.api.type.WxPayIndex2;
import com.liaoban.app.api.type.request.BdingReq;
import com.liaoban.app.update.UpdateRequest;
import com.liaoban.app.update.UpdateResponse;
import com.netease.nim.avchatkit.ui.SendGift;
import com.liaoban.app.api.type.ShareContent;
import com.liaoban.app.api.type.ShareIndex;
import com.liaoban.app.api.type.ShenYu;
import com.liaoban.app.api.type.Sms;
import com.liaoban.app.api.type.User;
import com.liaoban.app.api.type.Video;
import com.liaoban.app.api.type.WuserImg;
import com.liaoban.app.api.type.comment.BaseResponse;
import com.liaoban.app.api.type.request.ActiveCallEndReq;
import com.liaoban.app.api.type.request.AddReport;
import com.liaoban.app.api.type.request.BindReq;
import com.liaoban.app.api.type.request.CallFaQiReq;
import com.liaoban.app.api.type.request.EarnDetailRequest;
import com.liaoban.app.api.type.request.EarnRequest;
import com.liaoban.app.api.type.request.FeedBackRequest;
import com.liaoban.app.api.type.request.GiftRequest;
import com.liaoban.app.api.type.request.ImSendGiftReq;
import com.liaoban.app.api.type.request.ImgListRequest;
import com.liaoban.app.api.type.request.RankRequest;
import com.liaoban.app.api.type.request.SendGiftReq;
import com.liaoban.app.api.type.request.SendYuMoneyReq;
import com.liaoban.app.api.type.request.WuserTypeRequest;
import com.liaoban.app.api.type.request.ImgDelRequest;
import com.liaoban.app.api.type.request.LoginRequest;
import com.liaoban.app.api.type.request.RecommendRequest;
import com.liaoban.app.api.type.request.RegisterRequest;
import com.liaoban.app.api.type.request.SearchRequest;
import com.liaoban.app.api.type.request.SettingInfoRequest;
import com.liaoban.app.api.type.request.SmsRequest;
import com.liaoban.app.api.type.request.StatusSwitchRequest;
import com.liaoban.app.api.type.request.UpdatePwdRequest;
import com.liaoban.app.api.type.request.WuserinfoRequest;
import com.liaoban.app.constants.ConfigKey;
import com.liaoban.app.helper.ConfigHelper;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class CommonBiz {
    private static final CommonBiz ourInstance = new CommonBiz();

    public static CommonBiz getInstance() {
        return ourInstance;
    }

    private CommonBiz() {
    }

    public boolean isLogin(Context context) {
        String token = ConfigHelper.getString(context, ConfigKey.TOKEN);
        //token = "ybc"; //todo 临时添加，为了测试
        return !TextUtils.isEmpty(token);
    }

    /**
     * 首页banner
     *
     * @return
     */
    public Observable<BaseResponse<List<Banner>>> banner() {
        return HttpManager.getInstance().getHttpApi().banner();
    }

    /**
     * 登录
     *
     * @return
     */
    public Observable<BaseResponse<User>> login(LoginRequest loginRequest) {
        return HttpManager.getInstance().getHttpApi().login(loginRequest);
    }

    /**
     * 短信接口
     *
     * @param smsRequest
     * @return
     */
    public Observable<BaseResponse<Sms>> duanxin(SmsRequest smsRequest) {
        return HttpManager.getInstance().getHttpApi().duanxin(smsRequest);
    }

    /**
     * 修改密码
     *
     * @param updatePwdRequest
     * @return
     */
    public Observable<BaseResponse<Object>> updatePwd(UpdatePwdRequest updatePwdRequest) {
        return HttpManager.getInstance().getHttpApi().updatePwd(updatePwdRequest);
    }

    /**
     * 注册
     *
     * @param registerRequest
     * @return
     */
    public Observable<BaseResponse<Object>> register(RegisterRequest registerRequest) {
        return HttpManager.getInstance().getHttpApi().register(registerRequest);
    }

    /**
     * 个人中心
     *
     * @return
     */
    public Observable<BaseResponse<User>> userinfo() {
        return HttpManager.getInstance().getHttpApi().userinfo();
    }

    /**
     * 首页推荐位
     *
     * @param recommendRequest
     * @return
     */
    public Observable<BaseResponse<List<Anchor>>> recommend(RecommendRequest recommendRequest) {
        return HttpManager.getInstance().getHttpApi().recommend(recommendRequest);
    }

    /**
     * 分类名称
     *
     * @return
     */
    public Observable<BaseResponse<List<RecommendName>>> recommendName() {
        return HttpManager.getInstance().getHttpApi().recommendName();
    }

    /**
     * 分类推荐
     *
     * @param homePictureRequest
     * @return
     */
    public Observable<BaseResponse<List<Anchor>>> wuserType(WuserTypeRequest homePictureRequest) {
        return HttpManager.getInstance().getHttpApi().wuserType(homePictureRequest);
    }

    /**
     * 反馈
     *
     * @param feedBackRequest
     * @return
     */
    public Observable<BaseResponse<Object>> feedBack(FeedBackRequest feedBackRequest) {
        return HttpManager.getInstance().getHttpApi().feedBack(feedBackRequest);
    }

    /**
     * 编辑资料页面提交
     *
     * @param settingInfoRequest
     * @return
     */
    public Observable<BaseResponse<Object>> settingInfoSubmit(SettingInfoRequest settingInfoRequest) {
        return HttpManager.getInstance().getHttpApi().settingInfoSubmit(settingInfoRequest);
    }

    /**
     * 主播详情
     *
     * @param wuserinfoRequest
     * @return
     */
    public Observable<BaseResponse<Anchor>> wuserinfo(WuserinfoRequest wuserinfoRequest) {
        return HttpManager.getInstance().getHttpApi().wuserinfo(wuserinfoRequest);
    }

    /**
     * 主播详情
     *
     * @param wuserinfoRequest
     * @return
     */
    public Observable<BaseResponse<Anchor>> imUserInfo(WuserinfoRequest wuserinfoRequest) {
        return HttpManager.getInstance().getHttpApi().imUserInfo(wuserinfoRequest);
    }

    /**
     * 关注与取消关注主播
     *
     * @param wuserinfoRequest
     * @return
     */
    public Observable<BaseResponse<Object>> follow(WuserinfoRequest wuserinfoRequest) {
        return HttpManager.getInstance().getHttpApi().follow(wuserinfoRequest);
    }

    /**
     * 我的关注
     *
     * @return
     */
    public Observable<BaseResponse<List<Follow>>> myFollow() {
        return HttpManager.getInstance().getHttpApi().myFollow();
    }

    /**
     * 我的粉丝
     *
     * @return
     */
    public Observable<BaseResponse<List<Follow>>> myFans() {
        return HttpManager.getInstance().getHttpApi().myFans();
    }

    /**
     * 退出
     *
     * @return
     */
    public Observable<BaseResponse<BaseResponse>> logout() {
        return HttpManager.getInstance().getHttpApi().logout();
    }

    /**
     * 查看是否认证
     *
     * @return
     */
    public Observable<BaseResponse<Object>> isProve() {
        return HttpManager.getInstance().getHttpApi().isProve();
    }

    /**
     * 切换主播状态
     *
     * @return
     */
    public Observable<BaseResponse<Object>> statusSwitch(StatusSwitchRequest statusSwitchRequest) {
        return HttpManager.getInstance().getHttpApi().statusSwitch(statusSwitchRequest);
    }

    /**
     * 举报列表
     *
     * @return
     */
    public Observable<BaseResponse<List<Report>>> reportList() {
        return HttpManager.getInstance().getHttpApi().reportList();
    }

    /**
     * 魅力榜
     *
     * @return
     */
    public Observable<BaseResponse<List<Band>>> band() {
        return HttpManager.getInstance().getHttpApi().band();
    }

    /**
     * 认证
     *
     * @param imageFile 图片文件
     * @param videoFile 视频文件
     * @return
     */
    public Observable<BaseResponse<Object>> prove(File imageFile, File videoFile, File videoImg) {
        Map<String, RequestBody> map = new HashMap<>();
        RequestBody requestBodyImage = RequestBody.create(MediaType.parse("multipart/form-data"), imageFile);
        map.put("image\"; filename=\"" + imageFile.getName(), requestBodyImage);
        RequestBody requestBodyVideo = RequestBody.create(MediaType.parse("multipart/form-data"), videoFile);
        map.put("video\"; filename=\"" + videoFile.getName(), requestBodyVideo);
        RequestBody requestBodyVideoImg = RequestBody.create(MediaType.parse("multipart/form-data"), videoImg);
        map.put("video_img\"; filename=\"" + videoImg.getName(), requestBodyVideoImg);
        return HttpManager.getInstance().getHttpApi().prove(map);
    }

    /**
     * 举报提交
     *
     * @param addReport
     * @param reportImgFile 图片
     * @return
     */
    public Observable<BaseResponse<Object>> addReport(AddReport addReport, File reportImgFile) {
        Map<String, RequestBody> map = new HashMap<>();
        RequestBody requestBodyImage = RequestBody.create(MediaType.parse("multipart/form-data"), reportImgFile);
        map.put("report_img\"; filename=\"" + reportImgFile.getName(), requestBodyImage);
        map.put("wuser_id", RequestBody.create(MediaType.parse("text/plain"), addReport.getWuserId()));
        map.put("type", RequestBody.create(MediaType.parse("text/plain"), addReport.getType()));
        map.put("description", RequestBody.create(MediaType.parse("text/plain"), addReport.getDescription()));
        return HttpManager.getInstance().getHttpApi().addReport(map);
    }

    /**
     * 搜索
     *
     * @param searchRequest
     * @return
     */
    public Observable<BaseResponse<List<Follow>>> search(SearchRequest searchRequest) {
        return HttpManager.getInstance().getHttpApi().search(searchRequest);
    }

    /**
     * 头像上传
     *
     * @param avatarFile
     * @return
     */
    public Observable<BaseResponse<String>> headImgUpload(File avatarFile) {
        Map<String, RequestBody> map = new HashMap<>();
        RequestBody requestBodyImage = RequestBody.create(MediaType.parse("multipart/form-data"), avatarFile);
        map.put("head_img\"; filename=\"" + avatarFile.getName(), requestBodyImage);
        return HttpManager.getInstance().getHttpApi().headImgUpload(map);
    }

    /**
     * 聊伴主播秀（分类名称）
     *
     * @return
     */
    public Observable<BaseResponse<List<RecommendName>>> wuserListName() {
        return HttpManager.getInstance().getHttpApi().wuserListName();
    }

    /**
     * 聊伴主播秀（列表）
     *
     * @param homePictureRequest
     * @return
     */
    public Observable<BaseResponse<List<Anchor>>> wuserList(WuserTypeRequest homePictureRequest) {
        return HttpManager.getInstance().getHttpApi().wuserList(homePictureRequest);
    }

    /**
     * 我的相册
     *
     * @return
     */
    public Observable<BaseResponse<List<Img>>> imgList(ImgListRequest imgListRequest) {
        return HttpManager.getInstance().getHttpApi().imgList(imgListRequest);
    }

    /**
     * 我的视频
     *
     * @return
     */
    public Observable<BaseResponse<List<MyVideo>>> videoList(ImgListRequest imgListRequest) {
        return HttpManager.getInstance().getHttpApi().videoList(imgListRequest);
    }

    /**
     * 我的图册（上传图片）
     *
     * @param imgFile 图片
     * @return
     */
    public Observable<BaseResponse<Img>> imgUpload(File imgFile) {
        Map<String, RequestBody> map = new HashMap<>();
        RequestBody requestBodyImage = RequestBody.create(MediaType.parse("multipart/form-data"), imgFile);
        map.put("image\"; filename=\"" + imgFile.getName(), requestBodyImage);
        return HttpManager.getInstance().getHttpApi().imgUpload(map);
    }

    /**
     * 我的视频（上传视频）
     *
     * @param imgFile   封面
     * @param videoFile 视频
     * @return
     */
    public Observable<BaseResponse<MyVideo>> videoUpload(File imgFile, File videoFile) {
        Map<String, RequestBody> map = new HashMap<>();
        RequestBody requestBodyImage = RequestBody.create(MediaType.parse("multipart/form-data"), imgFile);
        map.put("image\"; filename=\"" + imgFile.getName(), requestBodyImage);
        RequestBody requestBodyVideo = RequestBody.create(MediaType.parse("multipart/form-data"), videoFile);
        map.put("video\"; filename=\"" + videoFile.getName(), requestBodyVideo);
        return HttpManager.getInstance().getHttpApi().videoUpload(map);
    }

    /**
     * 我的相册（删除）
     *
     * @param imgDelRequest
     * @return
     */
    public Observable<BaseResponse<Object>> imgDelete(ImgDelRequest imgDelRequest) {
        return HttpManager.getInstance().getHttpApi().imgDelete(imgDelRequest);
    }

    /**
     * 我的视频（删除）
     *
     * @param imgDelRequest
     * @return
     */
    public Observable<BaseResponse<Object>> videoDelete(ImgDelRequest imgDelRequest) {
        return HttpManager.getInstance().getHttpApi().videoDelete(imgDelRequest);
    }

    /**
     * 通话记录
     *
     * @return
     */
    public Observable<BaseResponse<List<CallHistory>>> callList() {
        return HttpManager.getInstance().getHttpApi().callList();
    }

    /**
     * 礼物
     *
     * @return
     */
    public Observable<BaseResponse<List<Gift>>> wuserGiftList(GiftRequest giftRequest) {
        return HttpManager.getInstance().getHttpApi().wuserGiftList(giftRequest);
    }

    /**
     * 视频
     *
     * @return
     */
    public Observable<BaseResponse<List<Video>>> wuserVideoList(GiftRequest giftRequest) {
        return HttpManager.getInstance().getHttpApi().wuserVideoList(giftRequest);
    }

    /**
     * 主播详情图片列表
     *
     * @return
     */
    public Observable<BaseResponse<List<WuserImg>>> wuserImgList(GiftRequest giftRequest) {
        return HttpManager.getInstance().getHttpApi().wuserImgList(giftRequest);
    }

    /**
     * 加入黑名单/移除黑名单
     *
     * @param wuserinfoRequest
     * @return
     */
    public Observable<BaseResponse<Object>> wuserBlack(WuserinfoRequest wuserinfoRequest) {
        return HttpManager.getInstance().getHttpApi().wuserBlack(wuserinfoRequest);
    }

    /**
     * 黑名单列表
     *
     * @return
     */
    public Observable<BaseResponse<List<Black>>> blackList() {
        return HttpManager.getInstance().getHttpApi().blackList();
    }

    /**
     * 排行榜
     *
     * @param rankRequest
     * @return
     */
    public Observable<BaseResponse<List<Rank>>> bandList(RankRequest rankRequest) {
        return HttpManager.getInstance().getHttpApi().bandList(rankRequest);
    }

    /**
     * 我的账单，我的收益
     *
     * @param earnRequest
     * @return
     */
    public Observable<BaseResponse<List<Earn>>> userMoney(EarnRequest earnRequest) {
        return HttpManager.getInstance().getHttpApi().userMoney(earnRequest);
    }

    /**
     * 账单详情
     *
     * @param earnDetailRequest
     * @return
     */
    public Observable<BaseResponse<Earn>> userMoneyDetails(EarnDetailRequest earnDetailRequest) {
        return HttpManager.getInstance().getHttpApi().userMoneyDetails(earnDetailRequest);
    }

    /**
     * 分享
     *
     * @return
     */
    public Observable<BaseResponse<ShareIndex>> shareIndex() {
        return HttpManager.getInstance().getHttpApi().shareIndex();
    }

    /**
     * 分享到
     *
     * @return
     */
    public Observable<BaseResponse<ShareContent>> share() {
        return HttpManager.getInstance().getHttpApi().share();
    }

    /**
     * 充值中心
     *
     * @return
     */
    public Observable<BaseResponse<PayIndex>> payIndex() {
        return HttpManager.getInstance().getHttpApi().payIndex();
    }

    /**
     * 充值接口
     *
     * @return
     */
    public Observable<BaseResponse<String>> payIndex2(PayIndex2Request payIndex2Request) {
        return HttpManager.getInstance().getHttpApi().payIndex2(payIndex2Request);
    }

    /**
     * 充值接口(微信)
     *
     * @return
     */
    public Observable<BaseResponse<WxPayIndex2>> payIndex2Wx(PayIndex2Request payIndex2Request) {
        return HttpManager.getInstance().getHttpApi().payIndex2Wx(payIndex2Request);
    }

    /**
     * 首页附近
     *
     * @return
     */
    public Observable<BaseResponse<List<Anchor>>> nearUser() {
        return HttpManager.getInstance().getHttpApi().nearUser();
    }

    /**
     * 消息通知
     *
     * @return
     */
    public Observable<BaseResponse<List<Notice>>> messageList() {
        return HttpManager.getInstance().getHttpApi().messageList();
    }

    /**
     * 消息中心
     *
     * @return
     */
    public Observable<BaseResponse<MessageIndex>> messageIndex() {
        return HttpManager.getInstance().getHttpApi().messageIndex();
    }

    /**
     * 支付完成查询余额
     *
     * @return
     */
    public Observable<BaseResponse<PayStatus>> payStatus() {
        return HttpManager.getInstance().getHttpApi().payStatus();
    }

    /**
     * im礼物打赏
     *
     * @param imSendGiftReq
     * @return
     */
    public Observable<BaseResponse<Integer>> imSendGift(ImSendGiftReq imSendGiftReq) {
        return HttpManager.getInstance().getHttpApi().imSendGift(imSendGiftReq);
    }

    /**
     * 通话第一步----发起通话
     *
     * @param callFaQiReq
     * @return
     */
    public Observable<BaseResponse<CallReq>> callFaQi(CallFaQiReq callFaQiReq) {
        return HttpManager.getInstance().getHttpApi().callFaQi(callFaQiReq);
    }

    /**
     * 通话第二步----接通
     *
     * @param callFaQiReq
     * @return
     */
    public Observable<BaseResponse<CallReq>> callJieTong(CallFaQiReq callFaQiReq) {
        return HttpManager.getInstance().getHttpApi().callJieTong(callFaQiReq);
    }

    /**
     * 通话第三部----挂断
     *
     * @return
     */
    public Observable<BaseResponse<Object>> activeCallEnd(ActiveCallEndReq activeCallEndReq) {
        return HttpManager.getInstance().getHttpApi().activeCallEnd(activeCallEndReq);
    }

    /**
     * 通话中刷礼物
     *
     * @param sendGiftReq
     * @return
     */
    public Observable<BaseResponse<SendGift>> sendGift(SendGiftReq sendGiftReq) {
        return HttpManager.getInstance().getHttpApi().sendGift(sendGiftReq);
    }

    /**
     * 查看是否可以提现
     *
     * @return
     */
    public Observable<BaseResponse<TiXian>> tixianStatus() {
        return HttpManager.getInstance().getHttpApi().tixianStatus();
    }

    /**
     * 绑定支付宝
     *
     * @param bindReq
     * @return
     */
    public Observable<BaseResponse<Object>> bangding(BindReq bindReq) {
        return HttpManager.getInstance().getHttpApi().bangding(bindReq);
    }

    /**
     * 通话中充值后查看剩余通话时长
     *
     * @param sendYuMoneyReq
     * @return
     */
    public Observable<BaseResponse<ShenYu>> sendYuMoney(SendYuMoneyReq sendYuMoneyReq) {
        return HttpManager.getInstance().getHttpApi().sendYuMoney(sendYuMoneyReq);
    }

    /**
     * 等级查看
     *
     * @return
     */
    public Observable<BaseResponse<List<Grade>>> grade() {
        return HttpManager.getInstance().getHttpApi().grade();
    }

    /**
     * 提现主页
     *
     * @return
     */
    public Observable<BaseResponse<Profit>> profit() {
        return HttpManager.getInstance().getHttpApi().profit();
    }

    /**
     * 分享提现--点击查看状态
     *
     * @return
     */
    public Observable<BaseResponse<ShareTixian>> shareTiXianStatus() {
        return HttpManager.getInstance().getHttpApi().shareTiXianStatus();
    }

    /**
     * 提现
     *
     * @return
     */
    public Observable<BaseResponse<Object>> tixian() {
        return HttpManager.getInstance().getHttpApi().tixian();
    }

    /**
     * 提现
     *
     * @return
     */
    public Observable<BaseResponse<Object>> shareTixian() {
        return HttpManager.getInstance().getHttpApi().shareTixian();
    }

    /**
     * 第三方授权等录
     *
     * @return
     */
    public Observable<BaseResponse<User>> threeLogin(ThreeLoginReq threeLoginReq) {
        return HttpManager.getInstance().getHttpApi().threeLogin(threeLoginReq);
    }

    /**
     * 微信绑定手机号
     *
     * @param bdingReq
     * @return
     */
    public Observable<BaseResponse<User>> bdingTell(BdingReq bdingReq) {
        return HttpManager.getInstance().getHttpApi().bdingTell(bdingReq);
    }

    /**
     * 升级
     *
     * @param updateRequest
     * @return
     */
    public Observable<BaseResponse<UpdateResponse>> version(UpdateRequest updateRequest) {
        return HttpManager.getInstance().getHttpApi().version(updateRequest);
    }
}
